from util.image_util import recognize_captcha
from selenium import webdriver
from time import sleep
from PIL import Image

url="http://wechat-rect.wechat-saas.192.168.8.90.nip.io:31078/"
code_img_path="images/code.png"

driver=webdriver.Chrome()
driver.get(url)
sleep(1)

driver.find_element_by_id("inputEmail").send_keys("13075819118")
driver.find_element_by_id("inputPassword").send_keys("123456")
code=driver.find_element_by_id("code")

driver.save_screenshot(code_img_path)

x=code.location['x']+164
y=code.location['y']+120
width=code.size['width']+10
height=code.size['height']
image=Image.open(code_img_path).crop((x,y,x+width,y+height)).save(code_img_path)

code=recognize_captcha(code_img_path)
print("获取的code："+code)
driver.find_element_by_id("check_pin").send_keys(code)
#点击登录
driver.find_element_by_id("submit").click()
#一秒后点击登录
sleep(1)
driver.find_elements_by_class_name("ant-btn").pop().click()

#sleep(10)
#driver.quit()
